﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cms.BLL.Menu;
using Cms.Entity.Article;
using Frame.Lib.Common;
using Cms.Common;
using Frame.Lib.Core.Attach;
using Frame.Lib.Utilities;
using Cms.BLL.Article;
using Cms.DAL;

namespace Cms.Admin.Attach
{


    public partial class Edit : PageEdit
    {
        private string MenuID
        {
            get
            {
                return Request["MenuID"];
            }
        }

        private ArticleBO _article;
        private ArticleBO Article
        {
            get
            {
                if (_article == null)
                {
                    _article = new ArticleBO();
                }
                return _article;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            btnSave.Attributes.Add("onclick", "showUploadMsg('" + lblMessage.ClientID + "','" + filAttach.ClientID + "');");
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (filAttach.FileName != "")
            {

                ArticleInfo info = Article.GetInfo(null);
                info.Name = System.IO.Path.GetFileName(filAttach.FileName);
                info.CreatorID = AppSession.UserID;
                info.CreatorName = AppSession.UserName;
                info.InputTime = DateTime.Now;
                info.IsDisplay = true;
                info.MenuID = int.Parse(MenuID);
                info.MenuName = new MenuBO().GetName(MenuID);
                info.UpdateTime = DateTime.Now;

                this.Article.Save(info);

                AttachBO attach = new AttachBO(CTableName.ArticleAttach);
                attach.Save(Request.Files, info.ID);
            }
            JSUtil.RefreshView();
        }
    }
}
